/* 
 * Copyright [2018] [Alex/libo(liboms@hotmail.com)]
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.apidoc.scanner;

import java.util.Objects;

import com.hyts.apidoc.bean.ScanBaseObject;
import com.hyts.apidoc.bean.ScanResultObject;



/** 
 * @title PackageScanner.java  
 * @package com.hyts.apidoc.scanner  
 * @description package 系统所有包的扫描类：扫描所有相关的文件类 
 * @see TODO
 * @author libo/Alex
 * @email liboms@hotmail.com/liboware@163.com  
 * @date 2018年4月18日 
 * @version V1.0 
 */
public class Scanner {

	/**  
	 * <p>{字段的描述}</p> 
	 * @fieldName jarScanner
	 * @fieldType JarScanner
	 */ 
	private JarScanner jarScanner;
	
	/**  
	 * <p>{字段的描述}</p> 
	 * @fieldName sourceScanner
	 * @fieldType SourceScanner
	 */ 
	private SourceScanner sourceScanner;
	
	/**  
	 * <p>扫描对象</p> 
	 * @fieldName scanObject
	 * @fieldType ScanBaseObject
	 */ 
	private ScanBaseObject scanObject;

	/**  
	 * @constructor：Scanner  
	 * @param jarScanner
	 * @param sourceScanner  
	 */ 
	public Scanner(ScanBaseObject obj) {
		this.jarScanner = new JarScanner();
		this.sourceScanner = new SourceScanner();
		this.scanObject = obj;
	}

	/**  
	 * @constructor：Scanner  
	 * @param sourceScanner  
	 */ 
	public Scanner(ScanBaseObject obj,SourceScanner sourceScanner) {
		super();
		this.sourceScanner = sourceScanner;
		this.scanObject = obj;
	}

	/**  
	 * @constructor：Scanner  
	 * @param jarScanner  
	 */ 
	public Scanner(ScanBaseObject obj,JarScanner jarScanner) {
		super();
		this.jarScanner = jarScanner;
		this.scanObject = obj;
	}
	
	/**  
	 * <b>scan:扫描服务对象信息</b>
	 * <p>扫描信息服务对象</p>
	 * @return ScanResultObject
	 * @exception
	 */ 
	public ScanResultObject scan() {
		ScanResultObject result = null;
		//检测进行扫描构建扫描器-只扫描jar包的源代码
		if(Objects.nonNull(this.jarScanner)) {
			result = jarScanner.scan(this.scanObject);
		}
		//检测进行构建扫描扫描器-项目内部文件源代码(不包含jar包中的文件)
		if(Objects.nonNull(this.sourceScanner)) {
			if(result == null)
				result = new ScanResultObject();
			result.addResultClass(this.sourceScanner.scan(this.scanObject).scanResultClass);
			result.addResultFile(this.sourceScanner.scan(this.scanObject).scanResultFile);
		}
		return result;
	}
	
}
